package com.yungu.swift.assets.driver.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.alicp.jetcache.anno.Cached;
import com.yungu.swift.assets.driver.dao.CarModelValuationMapper;
import com.yungu.swift.assets.driver.model.dto.CarModelValuationDto;
import com.yungu.swift.assets.driver.service.CarModelValuationService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.utils.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 计费规则业务逻辑处理接口实现类
 *
 * @author cuixiuyin - Generate
 * @version 1.1.1-SNAPSHOT
 * @since 2018-07-03 15:24
 */
@Service
public class CarModelValuationServiceImpl extends BaseServiceImpl<CarModelValuationDto> implements CarModelValuationService {

    @Autowired
    private CarModelValuationMapper carValuationMapper;

    @Override
    protected IMapper<CarModelValuationDto> getMapper() {
        return carValuationMapper;
    }


    @Override
    public ResponseData<CarModelValuationDto> getCarModel(Map<String, Object> map) {
        List<CarModelValuationDto> list = carValuationMapper.listCarModel(map);
        if (list != null && list.size() > 0) {
            return ResponseData.buildSuccessResponse(list.get(0));
        }
        return ResponseData.buildSuccessResponse(null);
    }

    @Override
    public ResponseData<List<CarModelValuationDto>> listRule(Map<String, Object> map) {
        return ResponseData.buildSuccessResponse(carValuationMapper.listRule(map));
    }

    @Override
    public ResponseData<List<CarModelValuationDto>> listTypeTime(Map<String, Object> map) {
        return ResponseData.buildSuccessResponse(carValuationMapper.listTypeTime(map));
    }

    @Override
    public int virtualDeleteModelsLevel(String businessUuid, String cityUuid) {
        return carValuationMapper.virtualDeleteModelsLevel(businessUuid, cityUuid);
    }

    @Override
    public ResponseData<Boolean> addBatch(List<CarModelValuationDto> carModelValuationdtoList) {
        if (carModelValuationdtoList == null || carModelValuationdtoList.isEmpty()) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "计价规则为空，添加失败");
        }
        if (carValuationMapper.addBatch(carModelValuationdtoList) > 0) {
            return ResponseData.buildSuccessResponse("计价规则添加成功", true);
        }
        return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "计价规则为空，添加失败");
    }

    @Cached(name = "jetCache:assets:getCarModelValuation:",key = "#uuid",expire = 150)
    @Override
    public ResponseData<CarModelValuationDto> get(String uuid) {
        return get(MapUtils.build("uuid", uuid));
    }
}